*
* @file
*/
+use MediaWiki\MediaWikiServices;
/**
* A query action to return meta information about the wiki site.
case 'languages':
$fit = $this->appendLanguages( $p );
break;
+ case 'languagevariants':
+ $fit = $this->appendLanguageVariants( $p );
+ break;
case 'skins':
$fit = $this->appendSkins( $p );
break;
$langCode = isset( $params['inlanguagecode'] ) ? $params['inlanguagecode'] : '';
$langNames = Language::fetchLanguageNames( $langCode );
- $getPrefixes = Interwiki::getAllPrefixes( $local );
+ $getPrefixes = MediaWikiServices::getInstance()->getInterwikiLookup()->getAllPrefixes( $local );
$extraLangPrefixes = $this->getConfig()->get( 'ExtraInterlanguageLinkPrefixes' );
$localInterwikis = $this->getConfig()->get( 'LocalInterwikis' );
$data = [];
$showHostnames = $this->getConfig()->get( 'ShowHostnames' );
if ( $includeAll ) {
if ( !$showHostnames ) {
- $this->dieUsage(
- 'Cannot view all servers info unless $wgShowHostnames is true',
- 'includeAllDenied'
- );
+ $this->dieWithError( 'apierror-siteinfo-includealldenied', 'includeAllDenied' );
}
$lags = $lb->getLagTimes();
return $this->getResult()->addValue( 'query', $property, $data );
}
+ // Export information about which page languages will trigger
+ // language conversion. (T153341)
+ public function appendLanguageVariants( $property ) {
+ $langNames = LanguageConverter::$languagesWithVariants;
+ if ( $this->getConfig()->get( 'DisableLangConversion' ) ) {
+ // Ensure result is empty if language conversion is disabled.
+ $langNames = [];
+ }
+ sort( $langNames );
+
+ $data = [];
+ foreach ( $langNames as $langCode ) {
+ $lang = Language::factory( $langCode );
+ if ( $lang->getConverter() instanceof FakeConverter ) {
+ // Only languages which do not return instances of
+ // FakeConverter implement language conversion.
+ continue;
+ }
+ $data[$langCode] = [];
+ ApiResult::setIndexedTagName( $data[$langCode], 'variant' );
+ ApiResult::setArrayType( $data[$langCode], 'kvp', 'code' );
+
+ $variants = $lang->getVariants();
+ sort( $variants );
+ foreach ( $variants as $v ) {
+ $fallbacks = $lang->getConverter()->getVariantFallbacks( $v );
+ if ( !is_array( $fallbacks ) ) {
+ $fallbacks = [ $fallbacks ];
+ }
+ $data[$langCode][$v] = [
+ 'fallbacks' => $fallbacks,
+ ];
+ ApiResult::setIndexedTagName(
+ $data[$langCode][$v]['fallbacks'], 'variant'
+ );
+ }
+ }
+ ApiResult::setIndexedTagName( $data, 'lang' );
+ ApiResult::setArrayType( $data, 'kvp', 'code' );
+
+ return $this->getResult()->addValue( 'query', $property, $data );
+ }
+
public function appendSkins( $property ) {
$data = [];
$allowed = Skin::getAllowedSkins();
}
public function appendProtocols( $property ) {
- // Make a copy of the global so we don't try to set the _element key of it - bug 45130
+ // Make a copy of the global so we don't try to set the _element key of it - T47130
$protocols = array_values( $this->getConfig()->get( 'UrlProtocols' ) );
ApiResult::setArrayType( $protocols, 'BCarray' );
ApiResult::setIndexedTagName( $protocols, 'p' );
'rightsinfo',
'restrictions',
'languages',
+ 'languagevariants',
'skins',
'extensiontags',
'functionhooks',